#include <iostream>
#include <cstdio>
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
using namespace std;
void WriteData(int wfd)
{
    char buf[1024];
    int count = 0;
    while (true)
    {
        snprintf(buf,sizeof(buf),"%d",count++);
        write(wfd,buf,strlen(buf));
        cout<<"write:"<<buf<<endl;
        sleep(1);
    }
    
}
void ReadData(int rfd)
{
    char buf[1024];
    while(true)
    {
        read(rfd,buf,sizeof(buf));
        cout<<"read:"<<buf<<endl;
    }
}
int main()
{
    int f[2];
    pipe(f);
    int id = fork();
    if(id == 0)
    {
        close(f[1]);
        ReadData(f[0]);
    }
    close(f[0]);
    WriteData(f[1]);
    waitpid(id,nullptr,0);
}